package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "分类品牌管理")
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    CategoryBrandService categoryBrandService;


    @Operation(summary = "根据第三级分类id，返回id集合（包含3个分类id）")
    @GetMapping("getIdsByCategory3Id/{category3Id}")
    public Result getIdsByCategory3Id(@PathVariable Long category3Id){
       List<Long> list =  categoryBrandService.getIdsByCategory3Id(category3Id);
       return  Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable Integer pageNum,@PathVariable Integer pageSize, @RequestBody CategoryBrandDto categoryBrandDto){
         PageInfo pageInfo = categoryBrandService.findByPage(pageNum,pageSize,categoryBrandDto);
         return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加品牌分类")
    @PostMapping("addCategoryBrand")
    public Result addCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.addCategoryBrand(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改品牌分类")
    @PutMapping("updateById")
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateById(categoryBrand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除品牌分类")
    @DeleteMapping("/deleteById/{id}")
    public Result deletedById(@PathVariable Long id){
        categoryBrandService.deletedById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
